﻿using System.Collections;
using System.Collections.Generic;
using PathologicalGames;
using UnityEngine;
using UnityEngine.UI;
using WorldOfSuperpowers_COMMON.DataModel;

public class ChooseSkillListContainer : MonoBehaviour
{
    public ScrollRect scrollRect;

    private SpawnPool IconPool;
    private Transform BPPoolIconPrefab;
    public Transform IconsParent;

    private Dictionary<ushort,Transform> IconInstanceDic = new Dictionary<ushort, Transform>();



    void Awake()
    {
        IconPool = PoolManager.Pools["SkillIcon"];
        BPPoolIconPrefab = IconPool.prefabs["ChooseSkillIcon"];
        IconsParent = transform.GetChild(0).Find("Content");
    }

    public void AddChooseSkill(ushort SkillID,bool isBan)
    {
        print("放入BP技能");
        Transform IconTran = IconPool.Spawn(BPPoolIconPrefab, IconsParent);
        ChooseSkillIcon PoolIcon = IconTran.GetComponent<ChooseSkillIcon>();
        PoolIcon.SetBPIconInfo(SkillID,isBan);
        IconInstanceDic.Add(SkillID, IconTran);
        //刷新滚动面板
        StartCoroutine(RefreshScroll());
    }

    IEnumerator RefreshScroll()
    {
        yield return new WaitForEndOfFrame();
        scrollRect.verticalNormalizedPosition = 0;
    }

    public void OnDisable()
    {
        IconInstanceDic.Clear();
    }
}
